package org.dfzt.common.util.minio;


import org.dfzt.common.util.MinioUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Minio文件上传配置文件
 */

@Configuration
public class MinioConfig {
    @Value(value = "${dfzt.minio.minio_url:#{null}}")
    private String minioUrl;
    @Value(value = "${dfzt.minio.minio_name:#{null}}")
    private String minioName;
    @Value(value = "${dfzt.minio.minio_pass:#{null}}")
    private String minioPass;
    @Value(value = "${dfzt.minio.bucketName:#{null}}")
    private String bucketName;
    @Value(value = "${dfzt.minio.imgSize:#{null}}")
    private Long imgSize;
    @Value(value = "${dfzt.minio.fileSize:#{null}}")
    private Long fileSize;

    @Bean
    public void initMinio(){
    	if(minioUrl == null) {
    		return;
    	}
        if(!minioUrl.startsWith("http")){
            minioUrl = "http://" + minioUrl;
        }
        if(!minioUrl.endsWith("/")){
            minioUrl = minioUrl.concat("/");
        }
        MinioUtil.setMinioUrl(minioUrl);
        MinioUtil.setMinioName(minioName);
        MinioUtil.setMinioPass(minioPass);
        MinioUtil.setBucketName(bucketName);
        MinioUtil.setImgSize(imgSize);
        MinioUtil.setFileSize(fileSize);
    }

}
